#include "internal.h"

static void FreeListInit(MemZone_t *seg)
{
    for (size_t i = 0; i < NR_PAGE_ORDERS; i++)
    {
        FreeArea_t *area = &seg->free_area[i];
        area->nr_free = 0;
        INIT_LIST_HEAD(&area->free_list[MIGRATE_UNMOVABLE]);
        INIT_LIST_HEAD(&area->free_list[MIGRATE_MOVABLE]);
        INIT_LIST_HEAD(&area->free_list[MIGRATE_RECLAIMABLE]);
    }
}

bool zone_init(MemZone_t *seg, uintptr_t start, size_t size,
               Page_t *pageBase)
{
    Page_t *page;
    size_t nPages = 0;
    size_t pageSize = 1 << PAGE_SHIFT;
    uintptr_t addr, sz;

    seg->zone_mem_map = pageBase;
    addr = (start + pageSize - 1) & ~(pageSize - 1); /* roundup */
    sz = size - (addr - start);

    sz = sz & ~(pageSize - 1); /* rounddown */

    FreeListInit(seg);

    seg->zone_start_pfn = addr >> PAGE_SHIFT;

    nPages = sz >> PAGE_SHIFT;
    seg->spanned_pages = nPages;

    for (size_t n = 0; n < nPages; n++)
    {
        __page_init_one(page, n);

        page++;
    }

    __zone_add_pages(seg, pageBase, nPages);

    return true;
}

void __free_pages(struct page *page, unsigned int order)
{

}

struct page *alloc_pages_noprof(gfp_t gfp_mask, unsigned int order)
{
    return NULL;
}
